const studentModel = require('../model/studentModel');
const classModel = require('../model/classModel');
module.exports.insert = async function(student){
    return await studentModel.create(student);
}

module.exports.find = async function(page,searchParams){
    // return await studentModel.find(searchParams);
    // console.log(page)
    let {current,pageSize} = page;

    // 根据查询条件获取总数
    let total = await studentModel.countDocuments(searchParams);
    // 根据查询条件获取具体数量的数据
    let data = await studentModel.find(searchParams)
                    .populate({path:"classes"})
                    .limit(pageSize)
                    .skip((current - 1) * pageSize);
    return {
        current,pageSize,total,rows:data,
    }
    
}

module.exports.findById = async function(id){
    return await studentModel.findById(id);
}

module.exports.delete = async function(id){
    return await studentModel.deleteOne({_id:id});
}

module.exports.update = async function(student){
    return await studentModel.updateOne({_id:student._id},student);
}

